<template>
  <div class="VPDocFooter">
    <div class="pager">
      <a
        class="pager-link prev"
        :class="{ disabled: !prevPage }"
        :href="prevPage ? prevPage.path : '#'"
        @click.prevent="prevPage && navigateTo(prevPage.path)"
        @mousemove="handleMouseMove"
        @mouseleave="handleMouseLeave"
      >
        <span class="title">上一页</span>
        <span class="desc">{{ prevPage ? prevPage.title : '无上一页' }}</span>
      </a>
      <a
        class="pager-link next"
        :class="{ disabled: !nextPage }"
        :href="nextPage ? nextPage.path : '#'"
        @click.prevent="nextPage && navigateTo(nextPage.path)"
        @mousemove="handleMouseMove"
        @mouseleave="handleMouseLeave"
      >
        <span class="title">下一页</span>
        <span class="desc">{{ nextPage ? nextPage.title : '无下一页' }}</span>
      </a>
    </div>
  </div>
</template>

<style scoped>
.VPDocFooter {
  padding: 32px 24px 48px;
}

.pager {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
}

.pager-link {
  display: flex;
  flex-direction: column;
  padding: 16px 20px;
  border: 1px solid #e5e7eb;
  transition: all 0.2s ease;
  height: 100%;
  position: relative;
  background-color: #ffffff;
  border-radius: 6px;
  overflow: hidden;
}

.pager-link::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: radial-gradient(
    circle at var(--mouse-x, 50%) var(--mouse-y, 50%),
    rgba(37, 99, 235, 0.5) 0%,
    rgba(37, 99, 235, 0) 60%
  );
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
}

.pager-link:hover {
  border-color: #3a8ee6;
  background-color: #f8fafc;
  transform: translateY(-2px);
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
}

.pager-link:hover::before {
  opacity: 1;
}

.pager-link.prev {
  text-align: left;
}

.pager-link.next {
  text-align: right;
}

.title {
  display: block;
  line-height: 24px;
  font-size: 16px;
  font-weight: 600;
  color: #2c3e50;
  margin-bottom: 8px;
  font-family:
    -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  letter-spacing: 0.02em;
}

.desc {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 24px;
  font-size: 14px;
  color: #64748b;
  font-family:
    -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  letter-spacing: 0.01em;
}

.pager-link.prev .desc {
  padding-right: 8px;
}

.pager-link.next .desc {
  padding-left: 8px;
  margin-left: auto;
}

/* 禁用状态样式 */
.pager-link.disabled {
  cursor: not-allowed;
  opacity: 0.6;
  background-color: #f8fafc;
  border-color: #e5e7eb;
}

.pager-link.disabled:hover {
  border-color: #e5e7eb;
  background-color: #f8fafc;
  transform: none;
  box-shadow: none;
}

.pager-link.disabled:hover::before {
  opacity: 0;
}

.pager-link.disabled .title,
.pager-link.disabled .desc {
  color: #94a3b8;
}

@media (max-width: 768px) {
  .VPDocFooter {
    padding: 24px 16px 32px;
  }

  .pager {
    grid-template-columns: 1fr;
    gap: 16px;
  }
}
</style>

<script setup lang="ts">
import { computed } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { mdRoutes } from '@/router'
import { getPrevNextPages } from '@/utils/PageNavUtil'

const route = useRoute()
const router = useRouter()

// 获取上一页和下一页信息
const prevPage = computed(() => {
  const { prev } = getPrevNextPages(route.path, mdRoutes)
  return prev
})

const nextPage = computed(() => {
  const { next } = getPrevNextPages(route.path, mdRoutes)
  return next
})

// 导航到指定页面
const navigateTo = (path: string) => {
  // 导航到新页面
  router.push(path).then(() => {
    // 在导航完成后滚动到页面顶部
    setTimeout(() => {
      window.scrollTo(0, 0)
    }, 0)
  })
}

// 鼠标跟随效果
const handleMouseMove = (event: MouseEvent) => {
  const target = event.currentTarget as HTMLElement
  const rect = target.getBoundingClientRect()
  const x = ((event.clientX - rect.left) / rect.width) * 100
  const y = ((event.clientY - rect.top) / rect.height) * 100

  // 设置鼠标跟随光晕的位置
  target.style.setProperty('--mouse-x', `${x}%`)
  target.style.setProperty('--mouse-y', `${y}%`)
}

const handleMouseLeave = (event: MouseEvent) => {
  const target = event.currentTarget as HTMLElement
  target.style.setProperty('--mouse-x', '50%')
  target.style.setProperty('--mouse-y', '50%')
}
</script>
